package com.goodving.guli.fragment;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.androidquery.AQuery;
import com.goodving.guli.R;
import com.goodving.guli.activity.MainFragmentActivity;
import com.goodving.guli.model.ViewPagerModel;
import com.goodving.guli.utility.C1076y;
import com.goodving.guli.utility.C1285g;
import com.goodving.guli.utility.C1460b;
import com.goodving.guli.utility.C1466h;
import com.goodving.guli.utility.C1483w;
import com.goodving.guli.utility.CalenderData;
import com.goodving.guli.utility.DailyInfoContainer;
import com.goodving.guli.utility.LdlDate;
import com.goodving.guli.utility.aa;

import java.util.ArrayList;
import java.util.Date;

/**
 * Created by Administrator on 2015-11-17.
 */
public class CalendarDailyFragment extends BaseFragment {
    public static final int resultCode = 123;
    private View mContainer;
    public int mCurrentPosition;
    private TextView mMonth;
    private ArrayList<DailyInfoContainer> mMonthDaily;
    private ViewPager mMonthViewPager;
    protected AQuery mQuery;
    private aa mViewPagerMonthAdapter;

    /* renamed from: cn.ledongli.ldl.fragment.CalendarDailyFragment.1 */
    class C13201 implements OnPageChangeListener {
        C13201() {
        }

        public void onPageScrolled(int i, float f, int i2) {
        }

        public void onPageSelected(int i) {
            CalendarDailyFragment.this.mCurrentPosition = i;
            CalendarDailyFragment.this.updateTitle(CalendarDailyFragment.this.mCurrentPosition);
        }

        public void onPageScrollStateChanged(int i) {
            if (i == 0) {
                CalendarDailyFragment.this.recomputeSelectedDayByMonthPosition(CalendarDailyFragment.this.mCurrentPosition);
                CalendarDailyFragment.this.updateCalendarViewPage(CalendarDailyFragment.this.mCurrentPosition);
            }
        }
    }

    public CalendarDailyFragment() {
        this.mCurrentPosition = 0;
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_month_daily, viewGroup, false);
        this.mQuery = new AQuery(getActivity());
        return inflate;
    }

    public void onActivityCreated(Bundle bundle) {
        super.onActivityCreated(bundle);
        createFragment();
        startAnimation();
    }

    private void startAnimation() {
        int a = C1483w.m12107a(getActivity());
        int a2 = C1483w.m12108a(getActivity(), 54.0f);
        float f = (float) a2;
        C1460b.m11918a(this.mContainer, 0.0f, (float) (a2 - a), 0.0f, f, 800);
    }

    private void createFragment() {
        initView();
        initDate();
        initListener();
    }

    private void initDate() {
        this.mMonthDaily = C1285g.m11509a(((ViewPagerModel) getArguments().getParcelable(ViewPagerFragment.SEND_DATE_TO_MONTH)).mCalenderDataList);
        this.mViewPagerMonthAdapter = new aa(getActivity(), this, this.mMonthDaily);
        this.mMonthViewPager.setAdapter(this.mViewPagerMonthAdapter);
        getCurrentPosition(((MainFragmentActivity) getActivity()).f4030u);
        this.mMonthViewPager.setCurrentItem(this.mCurrentPosition);
        updateTitle(this.mCurrentPosition);
    }

    private void initListener() {
        this.mMonthViewPager.setOnPageChangeListener(new C13201());
    }

    private void recomputeSelectedDayByMonthPosition(int i) {
        Date date = ((this.mMonthDaily.get(i)).getDailyInfoList().get(8)).f6087c;
        LdlDate c1211c = ((MainFragmentActivity) getActivity()).f4030u;
//        while (!date.m8871e(c1211c)) {
//            if (c1211c.after(date)) {
//                c1211c = c1211c.m8890w();
//            } else {
//                c1211c = c1211c.m8889v();
//            }
//        }
        ((MainFragmentActivity) getActivity()).f4030u = c1211c;
    }

    private void updateTitle(int i) {
        this.mMonth.setText(C1466h.m11955b(((DailyInfoContainer) this.mMonthDaily.get(i)).getMonth() + 1) + "\u6708");
    }

    private void initView() {
        this.mMonthViewPager = (ViewPager) ((AQuery) this.mQuery.id((int) R.id.viewpage_slide_month)).getView();
        this.mMonth = (TextView) ((AQuery) this.mQuery.id((int) R.id.tx_actionbar_month)).getView();
        ((AQuery) this.mQuery.id((int) R.id.ib_actinonbar_right)).clicked(this, "tapRightBtn");
        ((AQuery) this.mQuery.id((int) R.id.ib_actinonbar_left)).clicked(this, "tapLeftBtn");
        ((AQuery) this.mQuery.id((int) R.id.bt_today)).clicked(this, "tapTodayBtn");
        ((AQuery) this.mQuery.id((int) R.id.bt_tendency)).clicked(this, "tapTendency");
        this.mContainer = ((AQuery) this.mQuery.id((int) R.id.ll_month_container)).getView();
    }

    public void tapLeftBtn(View view) {
        int currentItem = this.mMonthViewPager.getCurrentItem();
        if (currentItem <= 0) {
            ((C1076y) getActivity()).m7646b("\u5df2\u7ecf\u5230\u6700\u65e9\u4e00\u6708");
        } else {
            this.mMonthViewPager.setCurrentItem(currentItem - 1);
        }
    }

    public void tapRightBtn(View view) {
        int currentItem = this.mMonthViewPager.getCurrentItem();
        if (currentItem >= this.mMonthDaily.size() - 1) {
            ((C1076y) getActivity()).m7646b("\u8bf7\u8010\u5fc3\u7b49\u5f85\uff0c\u4e0b\u6708\u5373\u5c06\u5230\u6765");
        } else {
            this.mMonthViewPager.setCurrentItem(currentItem + 1);
        }
    }

    private void updateCalendarViewPage(int i) {
//        C1041e c1041e = (C1041e) this.mViewPagerMonthAdapter.f3717a.get(i);
//        c1041e.m7590a(((MainFragmentActivity) getActivity()).f4030u);
//        c1041e.notifyDataSetChanged();
//        this.mViewPagerMonthAdapter.notifyDataSetChanged();
//        this.mMonthViewPager.setCurrentItem(i);
//        this.mCurrentPosition = i;
    }

    public void tapTodayBtn(View view) {
//        ((MainFragmentActivity) getActivity()).f4030u = LdlDate.m8856a();
//        ((MainFragmentActivity) getActivity()).m7827r();
    }

    private void getCurrentPosition(LdlDate c1211c) {
        for (int i = 0; i < this.mMonthDaily.size(); i++) {
            if (((CalenderData) ((DailyInfoContainer) this.mMonthDaily.get(i)).getDailyInfoList().get(8)).f6087c.m8871e(c1211c)) {
                this.mCurrentPosition = i;
                return;
            }
        }
    }

    public void tapTendency(View view) {
//        startActivity(new Intent(getActivity(), TrendActivity.class));
//        ((MainFragmentActivity) getActivity()).m7827r();
    }
}
